home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Ian & Stuart's Australian Mac: Not for Sale
/
Another.not.for.sale (Australia).iso
/
fade into you
/
getting there
/
Apps
/
MOO-1.7.6.src
/
src
/
log.c
< prev
next >
Wrap
Text File
|
1994-11-02
|
4KB
|
176 lines
/******************************************************************************
Copyright (c) 1992 Xerox Corporation. All rights reserved.
Portions of this code were written by Stephen White, aka ghond.
Use and copying of this software and preparation of derivative works based
upon this software are permitted. Any distribution of this software or
derivative works must comply with all applicable United States export
control laws. This software is made available AS IS, and Xerox Corporation
makes no warranty about the software, its performance or its conformity to
any specification. Any person obtaining a copy of this software is requested
to send their name and post office or electronic mail address to:
Pavel Curtis
Xerox PARC
3333 Coyote Hill Rd.
Palo Alto, CA 94304
Pavel@Xerox.Com
*****************************************************************************/
#include <errno.h>
#include "my-stdarg.h"
#include "my-stdio.h"
#include "my-string.h"
#include "my-time.h"
#include "config.h"
#include "functions.h"
#include "log.h"
#include "options.h"
#include "storage.h"
#include "streams.h"
#include "utils.h"
static void
do_log(const char *fmt, va_list args, const char *prefix)
{
time_t now = MacTime();
char *nowstr = ctime(&now);
nowstr[19] = '\0'; /* kill the year and newline at the end */
fprintf(stderr, "%s: %s", nowstr + 4, prefix); /* skip the day of week */
vfprintf(stderr, fmt, args);
fflush(stderr);
}
void
log(const char *fmt, ...)
{
va_list args;
va_start(args, fmt);
do_log(fmt, args, "");
va_end(args);
}
void
errlog(const char *fmt, ...)
{
va_list args;
va_start(args, fmt);
do_log(fmt, args, "*** ");
va_end(args);
}
void
log_perror(const char *what)
{
errlog("%s: %s\n", what, strerror(errno));
}
#ifdef LOG_COMMANDS
static Stream *command_history = 0;
#endif
void
reset_command_history()
{
#ifdef LOG_COMMANDS
if (command_history == 0)
command_history = new_stream(1024);
else
reset_stream(command_history);
#endif
}
void
log_command_history()
{
#ifdef LOG_COMMANDS
errlog("COMMAND HISTORY:\n%s", stream_contents(command_history));
#endif
}
void
add_command_to_history(Objid player, const char *command)
{
#ifdef LOG_COMMANDS
time_t now = MacTime();
char *nowstr = ctime(&now);
nowstr[19] = '\0'; /* kill the year and newline at the end */
stream_printf(command_history, "%s: #%d: %s\n",
nowstr + 4, /* skip day of week */
player, command);
#endif /* LOG_COMMANDS */
}
/**** built in functions ****/
static package
bf_server_log(Var arglist, Byte next, void *vdata, Objid progr)
{
if (!is_wizard(progr)) {
free_var(arglist);
return make_error_pack(E_PERM);
} else {
int is_error = 0;
Var ret;
ret.type = TYPE_NUM;
ret.v.num = 0;
if (arglist.v.list[0].v.num == 2)
is_error = is_true(arglist.v.list[2]);
if (is_error)
errlog("> %s\n", arglist.v.list[1].v.str);
else
log("> %s\n", arglist.v.list[1].v.str);
free_var(arglist);
return make_var_pack(ret);
}
}
void
register_log(void)
{
(void) register_function("server_log", 1, 2, bf_server_log,
TYPE_STR, TYPE_ANY);
}
char rcsid_log[] = "$Id: log.c,v 1.10 1992/10/23 23:03:47 pavel Exp $";
/* $Log: log.c,v $
* Revision 1.10 1992/10/23 23:03:47 pavel
* Added copyright notice.
*
* Revision 1.9 1992/10/21 03:02:35 pavel
* Converted to use new automatic configuration system.
*
* Revision 1.8 1992/09/22 22:48:15 pavel
* Added missing #include of "config.h".
*
* Revision 1.7 1992/09/08 22:04:45 pjames
* changed `register_bf_log()' to `register_log()'
*
* Revision 1.6 1992/08/20 17:27:13 pavel
* Added the prefix `> ' to all log messages generated by the server_log()
* built-in function, so that they can be distinguished from server-generated
* messages.
*
* Revision 1.5 1992/08/14 00:23:37 pavel
* Commented text after #endif.
*
* Revision 1.4 1992/08/11 17:27:58 pjames
* Changed server_log to return 0 instead of 1.
*
* Revision 1.3 1992/08/10 17:14:00 pjames
* Updated #includes. Added bf_server_log to write messages to server
* log output. Added registration procedure.
*
* Revision 1.2 1992/07/21 00:04:15 pavel
* Added rcsid_<filename-root> declaration to hold the RCS ident. string.
*
* Revision 1.1 1992/07/20 23:23:12 pavel
* Initial RCS-controlled version.
*/